#!/bin/bash

# 测试apisix的基本功能

echo "新增路由foo.com"
curl http://localhost:9080/alb/admin/routes/1 \
    -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
    -X PUT -i -d \
    '{
        "uri": "/*",
        "host": "foo.com",
        "upstream": {
            "type": "roundrobin",
            "nodes": {
                "172.21.32.152:6667": 1,
                "172.21.32.152:6668": 2
            }
        },
        "plugins": {
            "limit-count": {
                "count": 2,
                "time_window": 60,
                "rejected_code": 503,
                "key": "remote_addr"
            }
        }
    }'

echo "测试新增路由"
curl http://localhost:9080/alb/test/test_msg -H "host: foo.com"
curl http://localhost:9080/alb/test/test_msg -H "host: foo.com"
echo "测试路由中的插件"
curl http://localhost:9080/alb/test/test_msg -H "host: foo.com"


echo "新增路由bar.com"
curl http://localhost:9080/alb/admin/routes/1 \
    -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
    -X PUT -i -d \
    '{
        "uri": "/*",
        "host": "bar.com",
        "upstream": {
            "type": "roundrobin",
            "nodes": {
                "172.21.32.152:6667": 1,
                "172.21.32.152:6668": 2
            }
        }
    }'

echo "测试batch-requests路由"
curl --location --request POST 'http://127.0.0.1:9080/alb/batch-requests' \
    --header 'Content-Type: application/json' \
    --data '
 {
    "headers": {
        "Content-Type": "application/json",
        "host": "bar.com"
    },
    "timeout": 500,
    "pipeline": [
        {
            "path": "/alb/test/hello_1"
        },
        {
            "path": "/alb/test/hello_2"
        }
    ]}
'

